# -*- coding: utf-8 -*-
from multiproject.core.configuration import conf


def do_upgrade(env, cursor):
    try:
        name = conf.news_forum_name
        subject = conf.news_forum_subject
        description = conf.news_forum_description
    except:
        pass

    # check if the default forum already exists
    cursor.execute("SELECT COUNT(id) FROM forum WHERE name = %s", (name,))
    rows = cursor.fetchall()
    for row in rows:
        if int(row[0]) > 0:
            return

    # create the default forum
    cursor.execute("INSERT INTO forum (name, time, forum_group, author, moderators, "
                   "subscribers, subject, description) "
                   "VALUES (%s, UNIX_TIMESTAMP(NOW()), 0, 'trac', '', '', %s, %s)",
                   (name, subject, description))
